package com.xunyin.enums;

/**
 * 设备选项
 */
public enum DeviceOptEnum {

    /***
     * 电源
     */
    POWER_SUP(1, "电源"),

    /***
     * 灯光
     */
    LIGHT(2, "灯光"),

    /**
     * 空调
     */
    AIR_CONDI(3, "空调"),

    /**
     * 麻将机
     */
    MAHJONG(4, "麻将机"),

    /**
     * 桌球锁球器
     */
    TABLE_LOCK(5, "桌球锁球器");


    private final String name;

    private final int value;

    DeviceOptEnum(int value, String name) {
        this.name = name;
        this.value = value;
    }

    public int getValue() {
        return value;
    }

    public String getName() {
        return name;
    }

    public int getIndex() {
        return value;
    }

    public static DeviceOptEnum parse(Integer value) {
        if (value == null) {
            return throwParseException(value);
        }
        for (DeviceOptEnum e : DeviceOptEnum.values()) {
            if (e.getValue() == value) {
                return e;
            }
        }
        return throwParseException(value);
    }

    private static DeviceOptEnum throwParseException(Integer value) {
        throw new IllegalArgumentException(value + " can not parse to " + DeviceOptEnum.class.getName());
    }

    public static String getNameByValue(Integer value) {
        if (value == null) {
            return "";
        }
        for (DeviceOptEnum e : DeviceOptEnum.values()) {
            if (e.getValue() == value) {
                return e.getName();
            }
        }
        return "";
    }
}
